import java.util.Random;

public class Main {

    /**
     * m为合并的次数
     * @param uf
     * @param m
     * @return
     */
    private static double testUF(UF uf,int m){
        int size = uf.getSize();

        Random random = new Random();

        long startTime = System.nanoTime();

        for(int i = 0;i < m;i++){
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            uf.unionElements(a,b);
        }

        for(int i = 0;i < m;i++){
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            uf.isConnected(a,b);
        }

        long endTime = System.nanoTime();


        return (endTime - startTime)/1e9d;
    }

    public static void main(String[] args) {
        int size = 10000000;
        int m = 10000000;

//        UnionFind1 uf1 = new UnionFind1(size);
//        System.out.println("UnionFind1 : "+testUF(uf1,m)+" s");
//
//        UnionFind2 uf2 = new UnionFind2(size);
//        System.out.println("UnionFind2 : "+testUF(uf2,m)+" s");

        // int size = 100000;int m = 10000;
//        UnionFind1 : 0.438098172 s
//        UnionFind2 : 0.003609284 s

        UnionFind3 uf3 = new UnionFind3(size);
        System.out.println("UnionFind3 : "+testUF(uf3,m)+" s");

        UnionFind4 uf4 = new UnionFind4(size);
        System.out.println("UnionFind4 : "+testUF(uf4,m)+" s");

        UnionFind5 uf5 = new UnionFind5(size);
        System.out.println("UnionFind5 : "+testUF(uf5,m)+" s");

        UnionFind6 uf6 = new UnionFind6(size);
        System.out.println("UnionFind6 : "+testUF(uf6,m)+" s");



        // int size = 10000000;int m = 10000000;
//        UnionFind3 : 4.737330963 s
//        UnionFind4 : 4.574974024 s
//        UnionFind5 : 3.641691259 s
//        UnionFind6 : 4.078482963 s




    }
}
